<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace longbingcore\printer;

class Printer
{
    public static function FeiePrintMsg($config, $orderInfo, $apiname = "Open_printMsg", $time = 1)
    {
        $content = ["user" => $config["user"], "stime" => $_SERVER["REQUEST_TIME"], "sig" => sha1($config["user"] . $config["ukey"] . $_SERVER["REQUEST_TIME"]), "apiname" => $apiname, "sn" => $config["sn"], "content" => $orderInfo, "times" => $time];
        return self::getStream($content);
    }
    public static function FeieQueryOrderState($config, $index)
    {
        $msgInfo = ["user" => $config["user"], "stime" => $_SERVER["REQUEST_TIME"], "sig" => sha1($config["user"] . $config["ukey"] . $_SERVER["REQUEST_TIME"]), "apiname" => "Open_queryOrderState", "orderid" => $index];
        return self::getStream($msgInfo);
    }
    protected static function getStream($msgInfo)
    {
        $client = new HttpClient("api.feieyun.cn", 80);
        if(!$client->post("/Api/Open/", $msgInfo)) {
            return ["code" => false];
        }
        return json_decode($client->getContent(), true);
    }
    public static function action_print($partner, $machine_code, $content, $apiKey, $msign)
    {
        $param = ["partner" => $partner, "machine_code" => $machine_code, "time" => time()];
        $param["sign"] = self::generateSign($param, $apiKey, $msign);
        $param["content"] = $content;
        $str = self::getStr($param);
        return json_decode(self::sendCmd("http://open.10ss.net:8888", $str), true);
    }
    protected static function generateSign($params, $apiKey, $msign)
    {
        ksort($params);
        $stringToBeSigned = $apiKey;
        foreach ($params as $k => $v) {
            $stringToBeSigned .= urldecode($k . $v);
        }
        unset($k);
        unset($v);
        $stringToBeSigned .= $msign;
        return strtoupper(md5($stringToBeSigned));
    }
    protected static function getStr($param)
    {
        $str = "";
        foreach ($param as $key => $value) {
            $str = $str . $key . "=" . $value . "&";
        }
        $str = rtrim($str, "&");
        return $str;
    }
    protected static function sendCmd($url, $data)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($curl, CURLOPT_HTTPHEADER, ["Expect:"]);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_TIMEOUT, 30);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $tmpInfo = curl_exec($curl);
        if(curl_errno($curl)) {
            echo "Errno" . curl_error($curl);
        }
        curl_close($curl);
        return $tmpInfo;
    }
}

?>